package com.guangzhi.weijianzhi.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import com.guangzhi.weijianzhi.R;

public class GuiDeUiActivity extends BaseActivity implements OnClickListener {
	private Button button;
	private ViewPager view_pager;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.guide_layout);
		
		initView();
	}

	private void initView() {
		// TODO Auto-generated method stub
		view_pager = (ViewPager) findViewById(R.id.view_pager);
		button = (Button) findViewById(R.id.button);
		button.setOnClickListener(this);
		final List<View> lists = new ArrayList<View>();
		
		ImageView imageView1 = new ImageView(this);
		imageView1.setBackgroundResource(R.drawable.newguide1);
		
		ImageView imageView2 = new ImageView(this);
		imageView2.setBackgroundResource(R.drawable.newguide2);
		
		ImageView imageView3 = new ImageView(this);
		imageView3.setBackgroundResource(R.drawable.newguide3);
		
		ImageView imageView4 = new ImageView(this);
		imageView4.setBackgroundResource(R.drawable.newguide4);
		
		lists.add(imageView1);
		lists.add(imageView2);
		lists.add(imageView3);
		lists.add(imageView4);
		view_pager.setAdapter(new ViewPagerAdapter(lists));
		view_pager.setOnPageChangeListener(new OnPageChangeListener() {
			
			@Override
			public void onPageSelected(int arg0) {
				// TODO Auto-generated method stub
				if(arg0 ==3){
					button.setVisibility(View.VISIBLE);
				}else{
					button.setVisibility(View.GONE);
				}
			}
			
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
				 
			}
			
			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
				
			}
		});
	}
	  public class ViewPagerAdapter extends PagerAdapter{
	       private List<View> pages;
			public ViewPagerAdapter(List<View> lists) {
				this.pages = lists;
			}

			@Override
			public void destroyItem(ViewGroup container, int position, Object object) {
				// TODO Auto-generated method stub
				((ViewPager)container).removeView(pages.get(position));
			}

			@Override
			public Object instantiateItem(ViewGroup container, int position) {
				((ViewPager)container).addView(pages.get(position));
				return pages.get(position);
			}

			@Override
			public int getCount() {
				// TODO Auto-generated method stub
				return pages.size();
			}

			@Override
			public boolean isViewFromObject(View arg0, Object arg1) {
				// TODO Auto-generated method stub
				return arg0 == arg1 ;
			}
	    	
	    }
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		startActivity(new Intent(this,GuiDeUiTwoActivity.class));
		finish();
	}
}
